'The Following Constants may be passed to BrowseForFolder
'as vTopFolder or vSelPath
Public Const CSIDL_DESKTOP = &H0 'DeskTop
Public Const CSIDL_PROGRAMS = &H2 'Program Groups Folder
Public Const CSIDL_CONTROLS = &H3 'Control Panel Icons Folder
Public Const CSIDL_PRINTERS = &H4 'Printers Folder
Public Const CSIDL_PERSONAL = &H5 'Documents Folder
Public Const CSIDL_FAVORITES = &H6 'Favorites Folder
Public Const CSIDL_STARTUP = &H7 'Startup Folder
Public Const CSIDL_RECENT = &H8 'Recent folder
Public Const CSIDL_SENDTO = &H9 'SendTo Folder
Public Const CSIDL_BITBUCKET = &HA 'Recycle Bin Folder
Public Const CSIDL_STARTMENU = &HB 'Start Menu Folder
Public Const CSIDL_DESKTOPDIRECTORY = &H10 'Windows\Desktop Folder
Public Const CSIDL_DRIVES = &H11 'Devices Virtual Folder (My Computer)
Public Const CSIDL_NETWORK = &H12 'Network Neighborhood Virtual Folder
Public Const CSIDL_NETHOOD = &H13 'Network Neighborhood Folder
Public Const CSIDL_FONTS = &H14 'Fonts Folder
Public Const CSIDL_TEMPLATES = &H15 'ShellNew folder
Private Type SHItemID
cb As Long 'Size of the ID (including cb itself)
abID As Byte 'The item ID (variable length)
End Type
Private Type ItemIDList
mkid As SHItemID
End Type
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpCallbackProc As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
'Retrieves the location of a special (system) folder.
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ItemIDList) As Long
'ParseDisplayName function should be used instead of this undocumented function.
Private Declare Function SHSimpleIDListFromPath Lib "shell32" Alias "#162" (ByVal szPath As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function BrowseCallbackProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
Select Case uMsg
Case BFFM_INITIALIZED
' Set the dialog's pre-selected folder using the pidl
' set in bi.lParam and passed in the lpData param.
Public Function BrowseForFolder(hOwnerWnd As Long, Optional ByVal sInstruct As String, Optional vSelPath As Variant, Optional vTopFolder As Variant) As String
' Shows the Browse For Folder dialog
'
' hOwnerWnd (Long) OwnerWindow.hWnd.
' sInstruct (String) Instructions for user.
' vSelPath (String or CSIDL Constant) Pre-select this Folder.
' vTopFolder (String or CSIDL Constant) Set the Top folder.
'
' If successful, returns the selected folder's full path,
' returns an empty string otherwise.
'
Dim lRet As Long
Dim pidlRet As Long
Dim sPath As String * MAX_PATH
Dim lItemIDList As ItemIDList
Dim uBrowseInfo As BROWSEINFO
With uBrowseInfo
' The desktop will own the dialog
.hOwner = hOwnerWnd
' This will be the dialog's root folder.
If IsMissing(vTopFolder) Then
vTopFolder = CSIDL_DESKTOP
End If
If Len(vTopFolder) > 0 And Not IsNumeric(vTopFolder) Then
' Free the memory the shell allocated for the pidl.
Call CoTaskMemFree(pidlRet)
End If
' Free the memory the shell allocated for the pre-selected folder.
Call CoTaskMemFree(uBrowseInfo.lParam)
End Function
Public Function FarProc(lpProcName As Long) As Long
'Returns the value of the AddressOf operator
FarProc = lpProcName
End Function
Public Function GetInitEntry(ByVal sSection As String, ByVal sKeyName As String, Optional ByVal sDefault As String = "", Optional ByVal sInitFileName As String = "") As String
'This Function Reads In a String From The Init File.
'Returns Value From Init File or sDefault If No Value Exists.
'sDefault Defaults to an Empty String ("").
'Creates and Uses sDefInitFileName (AppPath\AppEXEName.Ini)
Public Function SetInitEntry(ByVal sSection As String, Optional ByVal sKeyName As String, Optional ByVal sValue As String, Optional ByVal sInitFileName As String = "") As Long
'This Function Writes a String To The Init File.
'Returns WritePrivateProfileString Success or Error.
'Creates and Uses sDefInitFileName (AppPath\AppEXEName.Ini)
'if sInitFileName Parameter Is Not Passed In.
'***** CAUTION *****
'If sValue is Null then sKeyName is deleted from the Init File.
'If sKeyName is Null then sSection is deleted from the Init File.